<%@ page import="pro4.Product, java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>搜索结果</title>
</head>
<body>
<h1>搜索结果</h1>

<%
    List<Product> results = (List<Product>) request.getAttribute("searchResults");
    if (results != null && !results.isEmpty()) {
%>
<ul>
    <% for (Product p : results) { %>
    <li>
        <%= p.getName() %> - ¥<%= p.getPrice() %>
        <form action="AddToCartServlet" method="post">
            <input type="hidden" name="id" value="<%= p.getId() %>">
            <input type="hidden" name="name" value="<%= p.getName() %>">
            <input type="hidden" name="price" value="<%= p.getPrice() %>">
            <input type="hidden" name="stock" value="<%= p.getStock() %>">
            <input type="hidden" name="imageUrl" value="<%= p.getImageUrl() %>">
            <button type="submit">加入购物车</button>
        </form>
    </li>
    <% } %>
</ul>
<% } else { %>
<p>未找到相关商品。</p>
<% } %>

<a href="cart.jsp">返回购物车</a>
</body>
</html>
